import java.util.ArrayList;
import java.util.Scanner;

public class TakeawayMethod {
    ArrayList<Takeaway> take = new ArrayList<>();
    ArrayList<Order> oktake = new ArrayList();
    Order okorder = new Order();
    Scanner sc = new Scanner(System.in);
    public void Orderfood(){
        take.add(new Takeaway(1,"红烧猪蹄",1,99,0));
        take.add(new Takeaway(2,"麻辣猪蹄",1,96,0));
        take.add(new Takeaway(3,"原味猪蹄",1,40,0));

        System.out.println("请输入订餐人的姓名!~~~");
        String rname = sc.next();
        okorder.setRname(rname);
        System.out.println("以下为菜品信息");
        for (int i = 0; i < take.size(); i++) {
            Takeaway takeaway = take.get(i);
            System.out.print(takeaway.getId()+"  ");
            System.out.print(takeaway.getName()+"  ");
            System.out.print(takeaway.getPrice()+"  ");
            System.out.println(takeaway.getThumbs()+"  ");
            System.out.println("----------------------------");
        }


            System.out.println("请输入菜品序号!~~~");
            int id = sc.nextInt();
            for (int i = 0; i < take.size(); i++){
                Takeaway takeaway = take.get(i);
                if (id==takeaway.getId()){
                    System.out.println(takeaway.getId());
                    okorder.setId(takeaway.getId());
                    okorder.setCname(takeaway.getName());
                    break;
                }
                else {
                    System.out.println("您输入的序号有误");
                }
           }


        System.out.println("请输入菜品份数!~~~");
        int portion = sc.nextInt();
        okorder.setPortion(portion);
        while (true) {
            System.out.println("送餐时间：要求当天10到20点间整点送餐，要求用户输入10~20的整数，输入错误，重复输入。");
            int time = sc.nextInt();
            if (time>10&&time<20){
                okorder.setTime(time);
                break;
            }
            else {
                System.out.println("时间错误请重新输入!~~");
            }
        }
        System.out.println("请输入送餐地址!~~~");
        String address= sc.next();
        okorder.setAddress(address);
        double sum = 0;//价格
        for (int i = 0; i <take.size(); i++) {
            Takeaway takeaway = take.get(i);
            if (okorder.getId()==takeaway.getId()){
                sum = (takeaway.getPrice()*portion);
            }
            else if(sum<50){
                sum = (takeaway.getPrice()*portion)-6;
            }
        }
        okorder.setSum(sum);
        String state = "已预定";
        okorder.setState(state);
        System.out.println("您的订单信息如下:~~");
        for (int i = 0; i <take.size(); i++) {
            Takeaway takeaway = take.get(i);
            if (okorder.getId()==takeaway.getId()){
                System.out.println("餐名:" + takeaway.getName());
                System.out.println("价格:" + sum);
            }
        }
        oktake.add(okorder);
    }

    public void showtake(){
        if (oktake.size()<1){
            System.out.println("您还没有任何订单");
            return;
        }
        System.out.println("您的订单如下");
        for (int i = 0; i <oktake.size() ; i++) {
            Order ok = oktake.get(i);
            System.out.println("您的食物id:"+ok.getId());
            System.out.println("您的名字:"+ok.getRname());
            System.out.println("食物的名字:"+ok.getCname());
            System.out.println("份数:"+ok.getPortion());
            System.out.println("订餐时间:"+ok.getTime());
            System.out.println("您的地址为:"+ok.getAddress());
            System.out.println("当前的状态:"+ok.getState());
        }
    }
    public void Signtake(){
        if (oktake.size()<1){
            System.out.println("您还没有任何订单");
            return;
        }
        while (true) {
            System.out.println("是否将您的订餐状态改为已完成! y/n");
            String date = sc.next();
            switch (date){
                case "y":
                    String state = "已完成";
                    okorder.setState(state);
                    return;
                case "n":
                    System.out.println("您的订单保持原状态!~~~");
                    return;
                default:
                    System.out.println("你输入的指令不正确请重新确认!~~");
                    break;
            }
        }
    }

    public void deletake(){
        if (oktake.size()<1){
            System.out.println("您还没有任何订单");
            return;
        }
        System.out.println("请您输入订单序号");
        int id = sc.nextInt();
        for (int i = 0; i <oktake.size(); i++) {
            if (id==okorder.getId()){
            if (okorder.getState().equals("已完成")){
                while (true) {
                    System.out.println("您的订单已完成是否要删除 y/n");
                    String date = sc.next();
                    switch (date){
                        case "y":
                            System.out.println("您的订单已删除");
                            oktake.remove(okorder);
                            return;
                        case "n":
                            System.out.println("您的订单保持原状态!~~~");
                            return;
                        default:
                            System.out.println("你输入的指令不正确请重新确认!~~");
                            break;
                    }
                }
            }
            else {
                oktake.remove(okorder);
                System.out.println("您的订单已删除");
                return;
            }
            }
        }
    }

    public void Thumbsup(){//点赞
        System.out.println("以下为菜品信息");
        for (int i = 0; i < take.size(); i++) {
            Takeaway takeaway = take.get(i);
            System.out.print(takeaway.getId()+"  ");
            System.out.print(takeaway.getName()+"  ");
            System.out.print(takeaway.getPrice()+"  ");
            System.out.println(takeaway.getThumbs()+"  ");
            System.out.println("----------------------------");
        }
        System.out.println("请您选择菜品序号进行点赞!~~");
        int date = sc.nextInt();
        for (int i = 0; i < take.size() ; i++) {
            Takeaway takeaway = take.get(i);
            int count = takeaway.getThumbs();
            if (date==takeaway.getId()){
                count++;
                takeaway.setThumbs(count);
                System.out.println("恭喜您点赞成功!~~");
            }
        }
    }

    public void start(){//控制台命令
        while (true) {
            System.out.println("欢迎使用”漂亮团外卖“");
            System.out.println("**************************************");
            System.out.println("1.我要订单");
            System.out.println("2.我的订单");
            System.out.println("3.签收订单");
            System.out.println("4.删除订单");
            System.out.println("5.我要点赞");
            System.out.println("6.我要退出系统");
            System.out.println("**************************************");
            int temp = sc.nextInt();
            switch (temp){
                case 1:
                    Orderfood();
                    break;
                case 2:
                    showtake();
                    break;
                case 3:
                    Signtake();
                    break;
                case 4:
                    deletake();
                    break;
                case 5:
                    Thumbsup();
                    break;
                case 6:
                    System.out.println("“谢谢使用，欢迎下次光临”");
                    return;
                default:
                    System.out.println("你输入的指令不对请重新确认");
                    break;
            }
        }
    }
}

















